package com.lanhe.admin.controller.versionRec;

import com.lanhe.common.annotation.Log;
import com.lanhe.common.constant.Constants;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.common.enums.BusinessType;
import com.lanhe.versionRec.domain.LhVersionRec;
import com.lanhe.versionRec.service.ILhVersionRecService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * app版本表(LhVersionRec)表控制层
 *
 * @author zhanggl
 * @since 2024-01-13 21:56:43
 */
@RestController
@RequestMapping("lhVersionRec")
public class LhVersionRecController extends BaseController {
	/**
	 * 服务对象
	 */
	@Resource
	private ILhVersionRecService lhVersionRecService;

	/**
	 * 分页查询所有数据
	 */
	@PreAuthorize("@ss.hasPermi('lhVersionRec:lhVersionRec:list')")
	@GetMapping("/list")
	public TableDataInfo list(LhVersionRec versionRec) {
		startPage();
		List<LhVersionRec> list = lhVersionRecService.selectVersionRecList(versionRec);
		for (LhVersionRec lhVersionRec : list) {
			lhVersionRec.setCanForceName(lhVersionRec.getCanForce().equals(Constants.GeneralIntType.ONE) ? "是" : "否");
		}
		return getDataTable(list);
	}


	/**
	 * 新增
	 *
	 * @param lhVersionRec 实体
	 * @author zhanggl
	 * @date 2024年01月13日22:11:13
	 */
	@PreAuthorize("@ss.hasPermi('lhVersionRec:lhVersionRec:add')")
	@Log(title = "APP版本管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@Validated @RequestBody LhVersionRec lhVersionRec) {
		return toAjax(lhVersionRecService.insertVersionRec(lhVersionRec));
	}

	/**
	 * 查询单个
	 *
	 * @param verId ID
	 * @author zhanggl
	 * @date 2024年01月13日22:12:12
	 */
	@PreAuthorize("@ss.hasPermi('lhVersionRec:lhVersionRec:query')")
	@GetMapping(value = "/{verId}")
	public AjaxResult getInfo(@PathVariable Long verId) {
		if (null == verId) {
			return error("ID不能为空");
		}
		return success(lhVersionRecService.selectVersionRecById(verId));
	}

	/**
	 * 修改
	 *
	 * @param lhVersionRec 实体
	 * @author zhanggl
	 * @date 2024年01月13日22:13:56
	 */
	@PreAuthorize("@ss.hasPermi('lhVersionRec:lhVersionRec:edit')")
	@Log(title = "APP版本管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@Validated @RequestBody LhVersionRec lhVersionRec) {
		if (null == lhVersionRec.getVerId()) {
			return error("ID不能为空");
		}
		return toAjax(lhVersionRecService.updateVersionRec(lhVersionRec));
	}

	/**
	 * 删除
	 *
	 * @param verId ID
	 * @author zhanggl
	 * @date 2023/12/4
	 */
	@PreAuthorize("@ss.hasPermi('lhVersionRec:lhVersionRec:remove')")
	@Log(title = "APP版本管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{verId}")
	public AjaxResult remove(@PathVariable Long verId) {
		if (null == verId) {
			return error("ID不能为空");
		}
		return toAjax(lhVersionRecService.deleteVersionRecById(verId));
	}


}

